<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title>算算省多少</title>
	<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
	<meta name="format-detection" content="telephone=no,email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="description" content="手机拍拍拍贷官网-中国领先互联网金融P2P网贷平台 提供网络贷款，投资理财 小额贷款,短期贷款,个人贷款,无抵押贷款服务 拍拍贷理财借贷投资，获得高年收益率回报，超低门槛，超高收益">
    <meta name="keywords" content="手机拍拍贷官网,拍拍贷,互联网金融,P2P借贷平台,还卡超人">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
	<div class="title">以下信息以最高评级计算，根据评级不同费率会有不同</div>
	<div class="main-wrap" style="width: 100%;overflow: hidden;">
		<div id="main">
			<div id="contain" style="margin-right: 0px;">
				<div id="value"></div>
			</div>
			<div id="unit">借款(元)</div>
			<div id="show">20000</div>
			<div id="track"></div>
		</div>
		<div class="items-month">
			<h3>分期(月)</h3>
			<div class="items J-item">
				<span class="index"><i>12</i></span>
				<span><i>6</i></span>
				<span><i>3</i></span>
			</div>
		</div>
	</div>
	<div class="sub-wrap">
		<div class="sub-item sub-item-1">
			<span>日费率</span>
			<strong><span class="J-profit">0.61</span><i>%</i></strong>
		</div>
		<div class="sub-item sub-item-1">
			<span>每月还款</span>
			<strong><span class="J-data-money">1.77</span>元</strong>
		</div>
		<div class="sub-item sub-item-2">
			<span>比信用卡省</span>
			<strong><span class="J-save-money">1500</span>元</strong>
		</div>
	</div>
	<div class="btn-wrap">
		<a href="http://m.ppdai.com/?hh#1">立即借款</a>
	</div>
 	
</body>
<script src="//m.ppdaicdn.com/act/huan/js/jquery.min.js"></script>
<script type="text/javascript">
	var scrollerTrack = {
		BODYWIDTH: 8000, //总宽度
		MAX: 100.0, //厘米最大值
		currentX: 0, //移动距离
		currentValue: 0, //移动的刻度数
		COUNT: 0, //厘米刻度数量
		SCALE: 10, //一厘米有多少毫米刻度
		Init: function() {
			var mWidth = scrollerTrack.BODYWIDTH; //刻度计总的宽度
			// document.getElementById("contain").style.width = mWidth + "px"; //主容器宽度
			//厘米刻度数量=最大值除以1
			var count = scrollerTrack.MAX / 1;
			//赋值厘米刻度数量
			scrollerTrack.COUNT = count;
			//一个厘米的宽度=总宽度除以厘米数量
			var itemWidth = mWidth / count;
			//一厘米有多少个毫米
			var scale = scrollerTrack.SCALE;
			//毫米宽度=一厘米宽度除以10
			var dialsWidth = itemWidth / 10;
			//循环渲染页面，显示刻度
			for(var i = 0; i < count; i++) {
				if(i==0) {
					var span_0 = document.createElement("strong");
					span_0.style.color = "#C5C5C5";
					span_0.innerHTML = 0 ;
					document.getElementById("value").appendChild(span_0)
				}
				var span = document.createElement("span");
				span.style.width = itemWidth + "px";
				span.style.marginLeft = i * itemWidth + "px";
				span.style.color = "#C5C5C5";
				span.innerHTML = '<i>'+(i + 1)*1000+'</i>' ;
				document.getElementById("value").appendChild(span);
				for(var r = 0; r < scale; r++) {
					var dials = document.createElement("span");
					dials.style.width = dialsWidth + "px";
					dials.style.marginLeft = r * dialsWidth + "px";
					//dials.style.height = 20 + "px";
					dials.style.left = 0;
					span.appendChild(dials);
				}
			}
			scrollerTrack.Value();
		},
		//取值
		Value: function() {
			scrollerTrack.InitPos();
			var isMoving = false;
			document.getElementById("contain").addEventListener('touchstart', function(e) {
				e.preventDefault();
				//点击屏幕时刻度尺的右margin值
				console.log('-------------')
				console.log(e)
				var val = parseInt(document.getElementById("contain").style.marginRight);
				//拖动开始时的x坐标，屏幕可以有多个触摸点，取一个
				var startX = e.touches[0];
				var downX = startX.clientX;
				isMoving = true;
				document.body.addEventListener('touchmove', function(event) {
					event.preventDefault();
					scrollerTrack.currentX = val;
					if(isMoving == false) return;
					//屏幕可以有多个触摸点，取一个
					var movedX = event.touches[0];
					var moveX = movedX.clientX;
					//移动的x轴距离=拖动开始的X坐标-拖动结束的X坐标，正数是左滑动，负数是右滑动
					var changeX = Math.ceil((downX - moveX)/8)*8;
					//左滑动
					if(changeX >= 0) {
						scrollerTrack.currentX += changeX;
					//右滑动取得正数
					} else {
					//取正数
						changeX = -changeX;
						scrollerTrack.currentX -= changeX;
					}
					if(scrollerTrack.currentX <= 0) {
						document.getElementById("contain").style.marginRight = 0;
						document.getElementById("show").innerHTML = 0;
						scrollerTrack.currentValue = 0;
						scrollerTrack.currentX = 0;
					} else if(scrollerTrack.currentX >= scrollerTrack.BODYWIDTH - 1) {
						document.getElementById("contain").style.marginRight = scrollerTrack.BODYWIDTH - 1 + "px";
						document.getElementById("show").innerHTML = scrollerTrack.MAX*1000;
						scrollerTrack.currentValue = scrollerTrack.MAX;
						scrollerTrack.currentX = scrollerTrack.MAX;
					} else {
						document.getElementById("contain").style.marginRight = scrollerTrack.currentX + "px";
						var v = scrollerTrack.MAX * (scrollerTrack.currentX / scrollerTrack.BODYWIDTH);
						document.getElementById("show").innerHTML = parseFloat(v).toFixed(1)*1000;
						scrollerTrack.currentValue = parseFloat(v).toFixed(1);
					}

				});

			});

			document.body.addEventListener('touchend', function() {
				suan_Month_hk();
				isMoving = false;
			});
		},
		InitPos:function(){
			document.getElementById("contain").style.marginRight = 20*80+'px';
			suan_Month_hk();
		}
	};
	window.onload = function() {
		scrollerTrack.Init()
	};
	var borrow_money,data_month,borrow_profit,data_money;
	function suan_Month_hk(){
		 borrow_money = document.getElementById("show").innerHTML; //借款金额
		 data_month = $('.J-item .index i').html();                  //还款月数
		 borrow_profit = $('.J-profit').html();                    //月利率
		 data_money = borrow_money*(1+borrow_profit)/data_month/10;   // 每月还款额
		 $('.J-data-money').html(data_money.toFixed(2));
	}
	$('.J-item span').on('click',function(){
		var _this = $(this);
		_this.siblings().removeClass('index');
		_this.addClass('index');
		suan_Month_hk();
	})
</script>
</html>